/******************************************************************************
	This file is a part of the Snapshot Bioinformatics Project

	Copyright (C) 2012-2013 Jarom Schow

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include "Taxon.h"

#include "SqlServer.h"

using namespace Bio;

/**
**/
struct Taxon::Data
{
	Data() : m_taxonId( -1 ), m_ncbiId( -1 ), m_parentId( -1 ), m_geneticCode( -1 ), 
		m_mitoCode( -1 ), m_left( -1 ), m_right( -1 ), m_parentLoaded( false ),
		m_childrenLoaded( false ), m_rank( Taxon::NoRank ), m_db( NULL ), m_parent( NULL )
	{}

	int					m_taxonId, m_ncbiId, m_parentId, m_geneticCode, m_mitoCode, m_left, m_right;
	bool				m_parentLoaded, m_childrenLoaded;
	Taxon::NodeRank	m_rank;
	QString				m_name;
	SqlServer			*m_db;
	Taxon				*m_parent;
	TaxonList			m_children;
};

/**
**/
Taxon::Taxon() : m_data( new Data )
{
}

/**
**/
Taxon::~Taxon()
{
	delete m_data;
	m_data = NULL;
}

/**
**/
void Taxon::setName( const QString &name )
{
	m_data->m_name = name;
}

/**
**/
QString Taxon::getName() const
{
	return m_data->m_name;
}

/**
**/
void Taxon::setTaxonId( int id )
{
	m_data->m_taxonId = id;
}

/**
**/
int Taxon::getTaxonId() const
{
	return m_data->m_taxonId;
}

/**
**/
void Taxon::setNcbiId( int id )
{
	m_data->m_ncbiId = id;
}

/**
**/
int Taxon::getNcbiId() const
{
	return m_data->m_ncbiId;
}

/**
**/
void Taxon::setParentId( int id )
{
	m_data->m_parentId = id;
}

/**
**/
int Taxon::getParentId() const
{
	return m_data->m_parentId;
}

/**
**/
void Taxon::setNodeRank( NodeRank rank )
{
	m_data->m_rank = rank;
}

/**
**/
Taxon::NodeRank Taxon::getNodeRank() const
{
	return m_data->m_rank;
}

/**
**/
void Taxon::setGeneticCode( int code )
{
	m_data->m_geneticCode = code;
}

/**
**/
int Taxon::getGeneticCode() const
{
	return m_data->m_geneticCode;
}

/**
**/
void Taxon::setMitoGeneticCode( int code )
{
	m_data->m_mitoCode = code;
}

/**
**/
int Taxon::getMitoGeneticCode() const
{
	return m_data->m_mitoCode;
}

/**
**/
void Taxon::setLeftValue( int left )
{
	m_data->m_left = left;
}

/**
**/
int Taxon::getLeftValue() const
{
	return m_data->m_left;
}

/**
**/
void Taxon::setRightValue( int right )
{
	m_data->m_right = right;
}

/**
**/
int Taxon::getRightValue() const
{
	return m_data->m_right;
}

/**
**/
Taxon* Taxon::getParent()
{
	/*
	if( !m_data->m_parentLoaded && m_data->m_db ){
		m_data->m_parent = m_data->m_db->getTaxonById( m_data->m_parentId );
		m_data->m_parentLoaded = true;
	}*/

	return m_data->m_parent;
}

/**
**/
TaxonList Taxon::getChildren()
{
	/*
	if( !m_data->m_childrenLoaded && m_data->m_db ){
		m_data->m_parent = m_data->m_db->getTaxonById( m_data->m_parentId );
		m_data->m_parentLoaded = true;
	}*/

	return m_data->m_children;
}
